#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int sorted_inc (int a[], int n) {
	int i;
	for (i = 0; i < n-1; i++) {
		if (a[i] > a[i+1] )
			return 0;
	}
	return 1;
}
void selection_sort (int a[], int n) {
	int t , i , j , min;
	for (i = 0; i < n ; i++) {
    min = i;
    for(j = i+1; j < n ; j++) { 
		if(a[j] < a[min])
			min = j;
    }
    t = a[min];
    a[min] = a[i];
    a[i] = t;
  }
}
void selection_sort_dec (int a[], int n) {
	int t , i , j , max;
	for (i = 0; i < n ; i++) {
    max = i;
    for(j = i+1; j < n ; j++) { 
		if(a[j] > a[max])
			max = j;
    }
    t = a[max];
    a[max] = a[i];
    a[i] = t;
  }
}
int main () {
	int n , i;
	printf ("Enter the array size: ");
	scanf ("%d",&n);	
	int a[n];
	printf ("Initial array\n");
	srand(time(NULL));
	for (i = 0 ; i < n ; i++) {
		a[i] = 1 + rand () % 100;
		printf ("%d\t",a[i]);
	}
	if (sorted_inc(a , n)) {
		printf ("\nthe array is sorted in increasing order");
		return 0;
	}
	printf ("\nthe array is not sorted in increasing order");
	printf ("\nSorted array in increasing order\n");
	selection_sort (a , n);
	for (i = 0 ; i < n ; i++)
		printf ("%d\t", a[i]);
	printf ("\nSorted array in decreasing order\n");
	selection_sort_dec (a , n);
	for (i = 0 ; i < n ; i++)
		printf ("%d\t", a[i]);
	return 0;
}
